/**
 *    Copyright 2009-2015 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.add;

import org.apache.ibatis.cache.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * @Author: ShipTang
 * @Description: 二级缓存
 * @Date: 2020/12/19 10:07
 */
public class CustomerCache implements Cache {

    public static final Map<Object, Object> map = new ConcurrentHashMap<>();

    /**
     * 对应的的namespace
     */
    private String id;

    public CustomerCache(String id) {
        this.id = id;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public void putObject(Object key, Object value) {
        System.out.println("----------putObject,id:"+key+"---------------,value:"+value);
        map.put(key, value);
    }

    @Override
    public Object getObject(Object key) {
        System.out.println("----------getObject,key:"+key+"---------------");
        return map.get(key);
    }

    @Override
    public Object removeObject(Object key) {
        return map.remove(key);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public int getSize() {
        return map.size();
    }

    @Override
    public ReadWriteLock getReadWriteLock() {
        return null;
    }

    public static Map<Object, Object> getMap() {
        return map;
    }
}
